<template>
  <el-container>
    <el-header>
      <el-row class="header-row">
        任务状态：
        <el-select v-model="conditions[0].value" placeholder="请选择" clearable>
          <el-option
            v-for="item in dir_tskstat"
            :key="item.id"
            :label="item.label"
            :value="item.data"
          />
        </el-select>
        <el-button class="table-header-btn" type="primary" icon="el-icon-search" @click="search">查询</el-button>
      </el-row>
    </el-header>
    <el-main>
      <el-table :data="taskList" stripe border style="width: 100%" empty-text="没有待处理任务">
        <el-table-column prop="tstkno" label="任务号" width="180" />
        <el-table-column prop="tskname" label="任务名称" />
        <el-table-column prop="procname" label="流程号" width="180" />
        <el-table-column prop="nodesn" label="节点号" width="180" />
        <el-table-column prop="node.nodename" label="节点名称" width="180" />
        <el-table-column label="任务状态">
          <template slot-scope="scope">
            {{key_tskstat[scope.row.tskstat]}}
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="180">
          <template slot-scope="scope">
            <el-button v-if="scope.row.tskstat === '0' || scope.row.tskstat === '1'" type="text" size="small" @click="toTask(scope.row)">处理</el-button>
            <el-button v-else type="text" size="small" >查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-main>

    <el-footer>
      <div class="block">
        <el-pagination
          :current-page="page.current"
          :page-sizes="[5,10, 20, 50, 100]"
          :page-size="page.size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="page.total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-footer>

  </el-container>
</template>
<script>
import request from '@/utils/request'
export default {
  data: function() {
    return {
      conditions: [
        {
          field: 'tskstat',
          type: 'STRING',
          value: '',
          symbol: 'EQ'
        }
      ],
      page: {
        current: 1,
        size: 5,
        total: 0
      },
      taskList: []
    }
  },
  computed: {
    key_logic: function() {
      const { logic = {}} = this.$store.state.directory.directoryItem
      return logic
    },
    key_tskstat: function () {
      const { tskstat = {}} = this.$store.state.directory.directoryItem
      return tskstat
    },
    dir_tskstat: function() {
      return this.$store.state.directory.directory['tskstat']
    }
  },
  created() {
    this.directoryUpdate()
    this.query()
  },
  methods: {
    directoryUpdate: function() {
      this.$store.commit('directory/setDirectory', 'logic')
      this.$store.commit('directory/setDirectory', 'tskstat')
    },
    // 转到详细任务信息
    toTask: function(row) {
      this.$router.push({ name: '任务处理', params: row })
    },
    // 每页显示数目发生变化时
    handleSizeChange: function(val) {
      this.page.size = val
      this.page.current = 1
      this.query()
    },
    // 当前页发生变化时
    handleCurrentChange: function(val) {
      this.page.current = val
      this.query()
    },
    // 搜索
    search: function() {
      this.page.current = 1
      this.query()
    },
    query: function() {
      this.$progress.start()
      this.page.conditions = this.conditions
      request({
        url: '/task/tasklist/queryCurrentUserTasks',
        method: 'post',
        data: this.page
      }).then(res => {
        this.$progress.done()
        if (res.result) {
          this.page.total = res.data.total
          this.taskList = res.data.data
        } else {
          this.$message.error(res.msg)
        }
      }).catch(() => { this.$progress.done() })
    }
  }
}
</script>
